///
//  Velocity v 1.0
//  Russell Lowke, January 31st 2011
//
//  Copyright (c) 2011 Lowke Media
//  see http://www.lowkemedia.com for more information
//
//  Permission is hereby granted, free of charge, to any person obtaining a 
//  copy of this software and associated documentation files (the "Software"), 
//  to deal in the Software without restriction, including without limitation 
//  the rights to use, copy, modify, merge, publish, distribute, sublicense, 
//  and/or sell copies of the Software, and to permit persons to whom the 
//  Software is furnished to do so, subject to the following conditions:
// 
//  The above copyright notice and this permission notice shall be included in 
//  all copies or substantial portions of the Software.
// 
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
//  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 
//  IN THE SOFTWARE. 
//
//

function Velocity(varName,				// (string) name of variable on target being modified
				  vel,					// (number) rate of change (delta/velocity)
				  min, 					// (number) minimum value of variable
				  max, 					// (number) maximum value of variable
				  type) 				// (string) type of effect, e.g. BaseFx.PERSIST
{
    this.varName = varName;             // (string) name of variable on target being modified
    this.vel = vel || 0;          		// (number) rate of change (delta/velocity)
    this.min = min || 0;          		// (number) minimum value of variable
    this.max = max || 0;          		// (number) maximum value of variable
    
    if (type) {                      // override type should be PERSIST, WRAP, REVERSE, END, or REMOVE
        this.type = type;
    }
    
    this.update = function()
    {
        // add velocity
        this.target[this.varName] += this.vel*this.timePassed;
        
        // if outside bounds return true
        if (this.target[this.varName] > this.max ||
            this.target[this.varName] < this.min) {
            return true;
        }
        
        return false;
    }
    
    this.wrap = function()
    {
        if (this.target[this.varName] > this.max) {
            this.target[this.varName] = this.min;
        } else if (this.target[this.varName] < this.min) {
            this.target[this.varName] = this.max;
        }
    }
    
    this.reverse = function()
    {
        if (this.target[this.varName] > this.max) {
            this.target[this.varName] = this.max;
        } else if (this.target[this.varName] < this.min) {
            this.target[this.varName] = this.min;
        }
        
        this.vel = -this.vel;
    }
}

Velocity.prototype = new BaseFx("Velocity", BaseFx.END);